function[]=ksquality(X,Y,f0,f1,prm)
%KSQUALITY  quality measures
%
%  ksquality(x,y,f0,f1)
%     [x,y] ... data set, x - the first group data
%                         y - the second group data
%      f0 ...... string, the density function for x (optional: default=[]=we don't know the function)
%      f1 ...... string, the density function for y (optional: default=[]=we don't know the function)
%
% (C) Jan Kolacek, Masaryk University (Czech Republic)

w=which('ksquality.m');
w(end-11:end)=[];
addpath(w);
addpath([w,'/regress']);
addpath([w,'/quality']);
addpath([w,'/distrib']);
addpath([w,'/bivardens']);
addpath([w,'/dens']);
addpath([w,'/dens/base']);
addpath([w,'/dens/functions']);

if nargin<1
    br=get(0,'DefaultFigureColor');
    %%v4colset;
    save v.mat br;
    
    callbackStr=['set(gcf,''CloseRequestFcn'',''closereq'');',...
        'load v.mat;if br~=[0 0 0] v5colset;end;', ...
        'clear;load puvprom;close(findobj(0,''Tag'',''kclos''));',...
        'delete v.mat;delete puvprom.mat;delete(gcf);'];
    
    crStr= 'save puvprom;';
    
    figure( ...
        'Visible','on', ...
        'Name','DATA LOADING', ...
        'CloseRequestFcn',callbackStr,...
        'Units','Normalized',...
        'CreateFcn',crStr,...
        'Tag','defprom',...
        'NumberTitle','off');
    
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.4,.85,.2,.1], ...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[1 0 0], ...
        'FontSize',0.5,...
        'String','Load Data');
    
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.1,.75,.3,.1], ...
        'HorizontalAlignment','left',...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.4,...
        'String','Select a file to load:');
    
    prom=char(who('-file','puvprom.mat'));
    S=whos('-file','puvprom.mat');
    idtxt=zeros(length(S),1);
    iddbl=zeros(length(S),1);
    for i=1:length(S)
        idtxt(i)=strcmp(S(i).class,'char');
        iddbl(i)=strcmp(S(i).class,'double');
    end
    promtxt=prom(logical(idtxt),:);
    promdbl=prom(logical(iddbl),:);
    
%     if size(prom,1)<2
%         rozh='off';
%     else
%         rozh='on';
%     end
rozh='off';
    switch size(promdbl,1)
        case 0
            promdbl=char('[]','[]');
        case 1
            promdbl=char(promdbl,'[]');
        otherwise
            rozh='on';
    end
    switch size(promtxt,1)
        case 0
            promtxt=char('[]','[]');
        case 1
            promtxt=char(promtxt,'[]');
    end
    
    % The BROWSE button
    call='uiopen(''LOAD'');prom=char(who);G=get(gcf,''userdata'');';
    call1=['if size(prom,1)>5 set([G(1),G(2),G(4),G(6)],''String'',prom);',...
        'set([G(1),G(2),G(4),G(6),G(7)],''Enable'',''on'');end;'];
    call2='G=get(gcf,''userdata'');ind=get(G(1),''Value'');prom=get(G(1),''String'');x_def=eval(prom(ind,:));';
    call3='G=get(gcf,''userdata'');ind=get(G(2),''Value'');prom=get(G(2),''String'');y_def=eval(prom(ind,:));';
    uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.4,.8,.1,0.07], ...
        'String','Browse', ...
        'Callback',[call,call1,call2,call3]);
    
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.1,.675,.3,.1], ...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.4,...
        'String','OR');
    
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.1,.6,.3,.1], ...
        'HorizontalAlignment','left',...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.4,...
        'String','Make a simulation:');
    
    % The SIMULATION button
    uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.4,.65,.1,0.07], ...
        'String','Simulation', ...
        'Callback','simulquality');
    
    uicontrol( ...
        'Style','frame', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.08,.38,.74,.24], ...
        'HorizontalAlignment','left',...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0]);
    
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.1,.49,.6,.1], ...
        'HorizontalAlignment','left',...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.4,...
        'String','Define the name of the variable for G0:');
    
    xHndl=uicontrol( ...
        'Style','popup', ...
        'Enable',rozh,...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.7,.55,.1,.04], ...
        'String',promdbl, ...
        'FontSize',0.7,...
        'CreateFcn','pr=get(gcbo,''string'');eval([''x_def='',pr(1,:),'';'']);clear pr;',...
        'Callback',['G=get(gcf,''userdata'');ind=get(G(1),''Value'');',...
        'prom=get(G(1),''String'');x_def=eval(prom(ind,:));']);
    %        'CreateFcn',['x_def=',prom(1,:),';'],...
    
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.1,.42,.6,.1], ...
        'HorizontalAlignment','left',...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.4,...
        'String','Write true density function (if known):');
    
    t0Hndl=uicontrol( ...
        'Style','edit', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.65,.47,.15,.05], ...
        'String','', ...
        'CreateFcn','f0_def=[];',...
        'HorizontalAlignment','left',...
        'Callback','G=get(gcf,''userdata'');f0_def=get(G(3),''String'');');
    
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.2,.4,.6,.05], ...
        'HorizontalAlignment','left',...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.8,...
        'String','or load the name from a variable: ');
    
    call1='G=get(gcf,''userdata'');ind=get(G(4),''Value'');prom=get(G(4),''String'');';
    call2='f0_def=eval(prom(ind,:));set(G(3),''String'',f0_def);';
    r0Hndl=uicontrol( ...
        'Style','popup', ...
        'Enable',rozh,...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.7,.41,.1,.04], ...
        'String',promtxt, ...
        'Value',2,...
        'FontSize',0.7,...
        'Callback',[call1,call2]);
    %        'CreateFcn',['y_def=',prom(2,:),';'],...
    
    uicontrol( ...
        'Style','frame', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.08,.13,.74,.24], ...
        'HorizontalAlignment','left',...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0]);
    
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.1,.25,.6,.1], ...
        'HorizontalAlignment','left',...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.4,...
        'String','Define the name of the variable for G1:');
    
    yHndl=uicontrol( ...
        'Style','popup', ...
        'Enable',rozh,...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.7,.31,.1,.04], ...
        'String',promdbl, ...
        'FontSize',0.7,...
        'Value',2,...
        'CreateFcn','pr=get(gcbo,''string'');eval([''y_def='',pr(2,:),'';'']);clear pr;',...
        'Callback',['G=get(gcf,''userdata'');ind=get(G(2),''Value'');',...
        'prom=get(G(2),''String'');y_def=eval(prom(ind,:));']);
    
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.1,.18,.6,.1], ...
        'HorizontalAlignment','left',...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.4,...
        'String','Write true density function (if known):');
    
    t1Hndl=uicontrol( ...
        'Style','edit', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.65,.23,.15,.05], ...
        'String','', ...
        'CreateFcn','f1_def=[];',...
        'HorizontalAlignment','left',...
        'Callback','G=get(gcf,''userdata'');f1_def=get(G(5),''String'');');
    
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.2,.16,.6,.05], ...
        'HorizontalAlignment','left',...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.8,...
        'String','or load the name from a variable: ');
    
    call1='G=get(gcf,''userdata'');ind=get(G(6),''Value'');prom=get(G(6),''String'');';
    call2='f1_def=eval(prom(ind,:));set(G(5),''String'',f1_def);';
    r1Hndl=uicontrol( ...
        'Style','popup', ...
        'Enable',rozh,...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.7,.17,.1,.04], ...
        'String',promtxt, ...
        'Value',2,...
        'FontSize',0.7,...
        'Callback',[call1,call2]);
    %        'CreateFcn',['y_def=',prom(2,:),';'],...
    
    % The CONTINUE button
    call='save pom.mat x_def y_def f0_def f1_def;close(gcf);load pom.mat;';
    call1=['if ischar(f0_def)&&ischar(f1_def) ksquality(x_def,y_def,f0_def,f1_def);',...
        'else ksquality(x_def,y_def);end;delete pom.mat;'];
    cHndl=uicontrol( ...
        'Style','push', ...
        'Enable',rozh,...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.83,.05,.1,0.07], ...
        'String','Continue', ...
        'Callback',[call,call1]);
    
    hndlList=[xHndl,yHndl,t0Hndl,r0Hndl,t1Hndl,r1Hndl,cHndl];
    set(gcf,'UserData',hndlList);
    %set(gcf,'Position',[0 0.0347 1.0000 0.9190]);
    set(gcf,'Position',[0.1059 0.1655 0.7700 0.6898]);
    
else
    %
    %     X1=X;Y1=Y;
    % X=X1;Y=Y1;clear X1 Y1;
    x=X(:)';y=Y(:)';
    X=x;Y=y;
    % M=length(x);
    % x=linspace(0,(M-1)/M,M);
    if nargin==5
        f0(f0==prm)='x';
        f1(f1==prm)='x';
    end;
    
    xx=X;xp=x;
    save w.mat x y X xx xp;
    % br=get(0,'DefaultFigureColor');
    
    callbackStr=['set(gcf,''CloseRequestFcn'',''closereq'');',...
        'load v.mat;', ...
        'clear;load puvprom;close(findobj(0,''Tag'',''kclos''));',...
        'delete v.mat;delete w.mat;delete puvprom.mat;delete(gcf);'];
    
    crStr= 'save puvprom;y_emp=[];y_ker=[];q=[];invec=[zeros(1,16),1];';
    % unts = get(0,'Units');
    % set(0,'Units','Normalized');
    % scrsz = get(0,'ScreenSize');
    % set(0,'Units',unts);
    %
    C=figure( ...
        'Visible','off', ...
        'Name','QUALITY INDEXES', ...
        'CloseRequestFcn',callbackStr,...
        'CreateFcn',crStr,...
        'NumberTitle','off',...
        'Units','Normalized');
    
    save v.mat C;
    axes( ...
        'Units','normalized', ...
        'Position',[0.08 0.08 0.66 0.7]);
    
    p0=plot(X,0,'bx');rr0='b--';
    hold on;
    p1=plot(Y,0,'ro');rr1='r--';
    legend([p0(1),p1(1)],'G_0 sample','G_1 sample');
    nX=min([X,Y]);mX=max([X,Y]);
    ff=0;
    if nargin>=5
        if ~isempty(f0)
            f0=strrep(f0,'x','t');
            f0=strrep(f0,'etp','exp');
            f1=strrep(f1,'x','t');
            f1=strrep(f1,'etp','exp');
            t=linspace(nX,mX);
            f0x=eval(vectorize(f0));
            f1x=eval(vectorize(f1));
            plot(t,f0x,rr0,t,f1x,rr1);ff=1;
            save v f0 f1 f0x f1x t -append;
        end
    end;
    hold off;
    hw = waitbar(0,'Please wait...');
    [r_emp,x_emp,F1_emp,F2_emp,xx_emp,KS_emp,Gini_emp,AUC_emp]=rocemp(X,Y);
    waitbar(1/10,hw);
    [r_ker,x_ker,F1_ker,x1_ker,F2_ker,x2_ker,KS_ker,Gini_ker,AUC_ker]=roc(X,Y);
    waitbar(2/10,hw);
    [ival_emp,iv_emp,xiv_emp,f1_emp,f2_emp] = ivemp(X,Y);
    waitbar(3/10,hw);
    [ival_ker,iv_ker,xiv_ker,f1_ker,f2_ker] = ivker(X,Y);
    waitbar(4/10,hw);
    [kr_emp,fkr_emp,xkr_emp]=kremp(X,Y);
    waitbar(5/10,hw);
    [kr_ker,fkr_ker,xkr_ker]=krker(X,Y);
    waitbar(6/10,hw);
    [lift_emp,flift_emp,xlift_emp,LR_emp,fLR_emp,IRL_emp,fIRL_emp,rand_emp]=liftemp(X,Y);
    waitbar(7/10,hw);
    [lift_ker,flift_ker,xlift_ker,LR_ker,fLR_ker,IRL_ker,fIRL_ker,rand_ker]=liftker(X,Y);
    waitbar(8/10,hw);
    save v ff rr0 rr1 nX mX -append;
    save v r_emp x_emp F1_emp F2_emp xx_emp KS_emp Gini_emp AUC_emp -append;
    save v r_ker x_ker F1_ker x1_ker F2_ker x2_ker KS_ker Gini_ker AUC_ker -append;
    save v ival_emp iv_emp xiv_emp f1_emp f2_emp -append;
    save v ival_ker iv_ker xiv_ker f1_ker f2_ker -append;
    save v kr_emp fkr_emp xkr_emp -append;
    save v kr_ker fkr_ker xkr_ker -append;
    save v lift_emp flift_emp xlift_emp LR_emp fLR_emp IRL_emp fIRL_emp rand_emp -append;
    save v lift_ker flift_ker xlift_ker LR_ker fLR_ker IRL_ker fIRL_ker rand_ker -append;
    waitbar(9/10,hw);
    k=length(X)/length([X,Y]);
    top=.85;
    fsz=0.7;
    fgc=[.7 0 0]; %Barva napisu
    bcgcol=[.8 .8 .8];
    waitbar(1,hw);
    close(hw);
    
    %    The ROC frame
    uicontrol( ...
        'Style','frame', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'String','ROC',...
        'BackgroundColor',bcgcol,...
        'Position',[0.075,top-.04,.16,.17]);
    
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'String','ROC',...
        'BackgroundColor',bcgcol,...
        'FontSize',fsz,...
        'Position',[0.08,top+.07,.15,.05], ...
        'ForegroundColor',fgc);
    
    callstr=['load v;hold off;plot(1-F1_emp,1-F2_emp);hold on;plot([0 1],[0 1],''k:'');',...
        'CH=num2str(AUC_emp,''%2.2f'');invec(1)=1;Hnd=get(gcf,''UserData'');',...
        'set(Hnd(18),''Enable'',''on'');set(Hnd(1),''String'',CH);'];
    
    uicontrol('Style','push','Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.08,top+.02,.08,.05], ...
        'Callback',callstr,...
        'String','empiric');
    
    callstr=['load v;hold off;plot(1-F1_ker,1-F2_ker,''r'');hold on;plot([0 1],[0 1],''k:'');',...
        'CH=num2str(AUC_ker,''%2.2f'');invec(2)=1;Hnd=get(gcf,''UserData'');',...
        'set(Hnd(18),''Enable'',''on'');set(Hnd(2),''String'',CH);'];
    
    uicontrol('Style','push','Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.08,top-.03,.08,.05], ...
        'Callback',callstr,...
        'String','kernel');
    
    roc_emp=uicontrol( ...
        'Style','text', ...
        'FontUnits','normalized',...
        'Units','normalized', ...
        'BackgroundColor',bcgcol,...
        'Position',[0.16,top+.02,.07,.05], ...
        'FontSize',fsz.*0.9,...
        'String','AUC');
    
    roc_ker=uicontrol( ...
        'Style','text', ...
        'FontUnits','normalized',...
        'Units','normalized', ...
        'BackgroundColor',bcgcol,...
        'Position',[0.16,top-.03,.07,.05], ...
        'FontSize',fsz.*0.9,...
        'String','AUC');
    
    %    The GINI frame
    uicontrol( ...
        'Style','frame', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'String','ROC',...
        'BackgroundColor',bcgcol,...
        'Position',[0.245,top-.04,.16,.17]);
    
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'String','Gini',...
        'BackgroundColor',bcgcol,...
        'FontSize',fsz,...
        'Position',[0.25,top+.07,.15,.05], ...
        'ForegroundColor',fgc);
    
    callstr=['load v;hold off;plot(1-F1_emp,1-F2_emp);hold on;plot([0 1],[0 1],''k:'');',...
        'CH=num2str(Gini_emp,''%2.2f'');invec(3)=1;Hnd=get(gcf,''UserData'');',...
        'set(Hnd(18),''Enable'',''on'');set(Hnd(3),''String'',CH);'];
    
    uicontrol('Style','push','Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.25,top+.02,.08,.05], ...
        'Callback',callstr,...
        'String','empiric');
    
    callstr=['load v;hold off;plot(1-F1_ker,1-F2_ker,''r'');hold on;plot([0 1],[0 1],''k:'');',...
        'CH=num2str(Gini_ker,''%2.2f'');invec(4)=1;Hnd=get(gcf,''UserData'');',...
        'set(Hnd(18),''Enable'',''on'');set(Hnd(4),''String'',CH);'];
 
    uicontrol('Style','push','Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.25,top-.03,.08,.05], ...
        'Callback',callstr,...
        'String','kernel');
    
    Gini_emp=uicontrol( ...
        'Style','text', ...
        'FontUnits','normalized',...
        'Units','normalized', ...
        'BackgroundColor',bcgcol,...
        'Position',[0.33,top+.02,.07,.05], ...
        'FontSize',fsz.*0.9,...
        'String','');
    
    Gini_ker=uicontrol( ...
        'Style','text', ...
        'FontUnits','normalized',...
        'Units','normalized', ...
        'BackgroundColor',bcgcol,...
        'Position',[0.33,top-.03,.07,.05], ...
        'FontSize',fsz.*0.9,...
        'String','');
    
    %    The KS frame
    uicontrol( ...
        'Style','frame', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'String','ROC',...
        'BackgroundColor',bcgcol,...
        'Position',[0.415,top-.04,.16,.17]);
    
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'String','MIS',...
        'BackgroundColor',bcgcol,...
        'FontSize',fsz,...
        'Position',[0.42,top+.07,.15,.05], ...
        'ForegroundColor',fgc);
    
    callstr=['load v;hold off;plot(xx_emp,F1_emp,xx_emp,F2_emp);legend(gca,''G_0'',''G_1'',''Location'',''SouthEast'');',...
        'CH=num2str(KS_emp,''%2.2f'');invec(5)=1;Hnd=get(gcf,''UserData'');',...
        'set(Hnd(18),''Enable'',''on'');set(Hnd(5),''String'',CH);'];
    
    uicontrol('Style','push','Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.42,top+.02,.08,.05], ...
        'Callback',callstr,...
        'String','empiric');
    
    callstr=['load v;hold off;plot(x1_ker,F1_ker,x2_ker,F2_ker);legend(gca,''G_0'',''G_1'',''Location'',''SouthEast'');',...
        'CH=num2str(KS_ker,''%2.2f'');invec(6)=1;Hnd=get(gcf,''UserData'');',...
        'set(Hnd(18),''Enable'',''on'');set(Hnd(6),''String'',CH);'];
    
    uicontrol('Style','push','Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.42,top-.03,.08,.05], ...
        'Callback',callstr,...
        'String','kernel');
    
    KS_emp=uicontrol( ...
        'Style','text', ...
        'FontUnits','normalized',...
        'Units','normalized', ...
        'BackgroundColor',bcgcol,...
        'Position',[0.5,top+.02,.07,.05], ...
        'FontSize',fsz.*0.9,...
        'String','');
    
    KS_ker=uicontrol( ...
        'Style','text', ...
        'FontUnits','normalized',...
        'Units','normalized', ...
        'BackgroundColor',bcgcol,...
        'Position',[0.5,top-.03,.07,.05], ...
        'FontSize',fsz.*0.9,...
        'String','');
    
    %    The Ival frame
    uicontrol( ...
        'Style','frame', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'BackgroundColor',bcgcol,...
        'Position',[0.585,top-.04,.16,.17]);
    
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'String','Inf. Value',...
        'BackgroundColor',bcgcol,...
        'FontSize',fsz,...
        'Position',[0.59,top+.07,.15,.05], ...
        'ForegroundColor',fgc);
    
    callstr=['load v;hold off;plot(xiv_emp,iv_emp);',...
        'CH=num2str(ival_emp,''%2.2f'');invec(7)=1;Hnd=get(gcf,''UserData'');',...
        'set(Hnd(18),''Enable'',''on'');set(Hnd(7),''String'',CH);'];
    
    uicontrol('Style','push','Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.59,top+.02,.08,.05], ...
        'Callback',callstr,...
        'String','empiric');
    
    callstr=['load v;hold off;plot(xiv_ker,iv_ker,''r'');',...
        'CH=num2str(ival_ker,''%2.2f'');invec(8)=1;Hnd=get(gcf,''UserData'');',...
        'set(Hnd(18),''Enable'',''on'');set(Hnd(8),''String'',CH);'];
    
    uicontrol('Style','push','Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.59,top-.03,.08,.05], ...
        'Callback',callstr,...
        'String','kernel');
    
    IV_emp=uicontrol( ...
        'Style','text', ...
        'FontUnits','normalized',...
        'Units','normalized', ...
        'BackgroundColor',bcgcol,...
        'Position',[0.67,top+.02,.07,.05], ...
        'FontSize',fsz.*0.9,...
        'String','');
    
    IV_ker=uicontrol( ...
        'Style','text', ...
        'FontUnits','normalized',...
        'Units','normalized', ...
        'BackgroundColor',bcgcol,...
        'Position',[0.67,top-.03,.07,.05], ...
        'FontSize',fsz.*0.9,...
        'String','');
    
    %    The KR frame
    uicontrol( ...
        'Style','frame', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'BackgroundColor',bcgcol,...
        'Position',[0.755,top-.04,.16,.17]);
    
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'String','KR',...
        'BackgroundColor',bcgcol,...
        'FontSize',fsz,...
        'Position',[0.76,top+.07,.15,.05], ...
        'ForegroundColor',fgc);
    
    callstr=['load v;hold off;plot(xkr_emp,fkr_emp);',...
        'CH=num2str(kr_emp,''%2.2f'');invec(9)=1;Hnd=get(gcf,''UserData'');',...
        'set(Hnd(18),''Enable'',''on'');set(Hnd(9),''String'',CH);'];
    
    uicontrol('Style','push','Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.76,top+.02,.08,.05], ...
        'Callback',callstr,...
        'String','empiric');
    
    callstr=['load v;hold off;plot(xkr_ker,fkr_ker,''r'');',...
        'CH=num2str(kr_ker,''%2.2f'');invec(10)=1;Hnd=get(gcf,''UserData'');',...
        'set(Hnd(18),''Enable'',''on'');set(Hnd(10),''String'',CH);'];
    
    uicontrol('Style','push','Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.76,top-.03,.08,.05], ...
        'Callback',callstr,...
        'String','kernel');
    
    KR_emp=uicontrol( ...
        'Style','text', ...
        'FontUnits','normalized',...
        'Units','normalized', ...
        'BackgroundColor',bcgcol,...
        'Position',[0.84,top+.02,.07,.05], ...
        'FontSize',fsz.*0.9,...
        'String','');
    
    KR_ker=uicontrol( ...
        'Style','text', ...
        'FontUnits','normalized',...
        'Units','normalized', ...
        'BackgroundColor',bcgcol,...
        'Position',[0.84,top-.03,.07,.05], ...
        'FontSize',fsz.*0.9,...
        'String','');
    
    %    The Lift frame
    top = top - 0.05;
    uicontrol( ...
        'Style','frame', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'BackgroundColor',bcgcol,...
        'Position',[0.755,top-.58,.16,.56]);
    
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'String','Lift',...
        'BackgroundColor',bcgcol,...
        'FontSize',fsz,...
        'Position',[0.76,top-.08,.15,.05], ...
        'ForegroundColor',fgc);
    
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'String','Set q:',...
        'HorizontalAlignment','right',...
        'BackgroundColor',bcgcol,...
        'Position',[0.76,top-.13,.08,.05]);
    
    qHndl=uicontrol( ...
        'Style','edit', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'String',num2str(k,'%0.2g'),...
        'Value',k,...
        'Callback','k=get(gco,''String'');set(gco,''Value'',str2num(k));',...
        'Position',[0.85,top-.12,.05,.04]);
    
    callstr=['load v;hold off;plot(xlift_emp,flift_emp);Hnd=get(gcf,''UserData'');',...
        'q=get(Hnd(17),''Value'');y_emp=qlift(xlift_emp,flift_emp,q,gcf);CH=num2str(y_emp,''%2.2f'');',...
        'set(Hnd(11),''String'',CH);invec(11)=1;set(Hnd(18),''Enable'',''on'');'];
    
    uicontrol('Style','push','Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.76,top-.18,.08,.05], ...
        'Callback',callstr,...
        'String','empiric');
    
    callstr=['load v;hold off;plot(xlift_ker,flift_ker,''r'');Hnd=get(gcf,''UserData'');',...
        'q=get(Hnd(17),''Value'');y_ker=qlift(xlift_ker,flift_ker,q,gcf);CH=num2str(y_ker,''%2.2f'');',...
        'set(Hnd(12),''String'',CH);invec(12)=1;set(Hnd(18),''Enable'',''on'');'];
    
    uicontrol('Style','push','Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.76,top-.23,.08,.05], ...
        'Callback',callstr,...
        'String','kernel');
    
    Lift_emp=uicontrol( ...
        'Style','text', ...
        'FontUnits','normalized',...
        'Units','normalized', ...
        'BackgroundColor',bcgcol,...
        'Position',[0.84,top-.18,.07,.05], ...
        'FontSize',fsz.*0.9,...
        'String','');
    
    Lift_ker=uicontrol( ...
        'Style','text', ...
        'FontUnits','normalized',...
        'Units','normalized', ...
        'BackgroundColor',bcgcol,...
        'Position',[0.84,top-.23,.07,.05], ...
        'FontSize',fsz.*0.9,...
        'String','');
    
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'String','LR',...
        'BackgroundColor',bcgcol,...
        'FontSize',fsz,...
        'Position',[0.76,top-.3,.15,.05], ...
        'ForegroundColor',fgc);
    
    callstr=['load v;hold off;p1=plot(xlift_emp,flift_emp);hold on;p2=plot(xlift_emp,fLR_emp,''r'');',...
        'legend([p1,p2],''Qlift'',''Ideal Qlift'');CH=num2str(LR_emp,''%2.2f'');',...
        'Hnd=get(gcf,''UserData'');set(Hnd(13),''String'',CH);invec(13)=1;set(Hnd(18),''Enable'',''on'');'];
    
    uicontrol('Style','push','Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.76,top-.35,.08,.05], ...
        'Callback',callstr,...
        'String','empiric');
    
    callstr=['load v;hold off;p1=plot(xlift_ker,flift_ker);hold on;p2=plot(xlift_ker,fLR_ker,''r'');',...
        'legend([p1,p2],''Qlift'',''Ideal Qlift'');CH=num2str(LR_ker,''%2.2f'');',...
        'Hnd=get(gcf,''UserData'');set(Hnd(14),''String'',CH);invec(14)=1;set(Hnd(18),''Enable'',''on'');'];
    
    uicontrol('Style','push','Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.76,top-.4,.08,.05], ...
        'Callback',callstr,...
        'String','kernel');
    
    LR_emp=uicontrol( ...
        'Style','text', ...
        'FontUnits','normalized',...
        'Units','normalized', ...
        'BackgroundColor',bcgcol,...
        'Position',[0.84,top-.35,.07,.05], ...
        'FontSize',fsz.*0.9,...
        'String','');
    
    LR_ker=uicontrol( ...
        'Style','text', ...
        'FontUnits','normalized',...
        'Units','normalized', ...
        'BackgroundColor',bcgcol,...
        'Position',[0.84,top-.4,.07,.05], ...
        'FontSize',fsz.*0.9,...
        'String','');
    
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'String','IRL',...
        'BackgroundColor',bcgcol,...
        'FontSize',fsz,...
        'Position',[0.76,top-.47,.15,.05], ...
        'ForegroundColor',fgc);
    
    callstr=['load v;hold off;p1=plot(xlift_emp,fIRL_emp);hold on;p2=plot(xlift_emp,rand_emp,''m'');',...
        'legend([p1,p2],''Rlift'',''Random'');CH=num2str(IRL_emp,''%2.2f'');',...
        'Hnd=get(gcf,''UserData'');set(Hnd(15),''String'',CH);invec(15)=1;set(Hnd(18),''Enable'',''on'');'];
    
    uicontrol('Style','push','Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.76,top-.52,.08,.05], ...
        'Callback',callstr,...
        'String','empiric');
    
    callstr=['load v;hold off;p1=plot(xlift_ker,fIRL_ker);hold on;p2=plot(xlift_ker,rand_ker,''m'');',...
        'legend([p1,p2],''Rlift'',''Random'');CH=num2str(IRL_ker,''%2.2f'');',...
        'Hnd=get(gcf,''UserData'');set(Hnd(16),''String'',CH);invec(16)=1;set(Hnd(18),''Enable'',''on'');'];
    
    uicontrol('Style','push','Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.76,top-.57,.08,.05], ...
        'Callback',callstr,...
        'String','kernel');
    
    IRL_emp=uicontrol( ...
        'Style','text', ...
        'FontUnits','normalized',...
        'Units','normalized', ...
        'BackgroundColor',bcgcol,...
        'Position',[0.84,top-.52,.07,.05], ...
        'FontSize',fsz.*0.9,...
        'String','');
    
    IRL_ker=uicontrol( ...
        'Style','text', ...
        'FontUnits','normalized',...
        'Units','normalized', ...
        'BackgroundColor',bcgcol,...
        'Position',[0.84,top-.57,.07,.05], ...
        'FontSize',fsz.*0.9,...
        'String','');
    
    % The SAVE text
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.88,.15,.1,.04], ...
        'BackgroundColor',bcgcol, ...
        'String','Save Data:');
    
    % The VAR button
    call=['load v;load w; checkLabels = {''Save empiric AUC to variable named:'','...
        '''Save kernel AUC to variable named:'',',...
        '''Save empiric Gini to variable named:'',',...
        '''Save kernel Gini to variable named:'',',...
        '''Save empiric KS to variable named:'',',...
        '''Save kernel KS to variable named:'',',...
        '''Save empiric Information value to variable named:'',',...
        '''Save kernel Information value to variable named:'',',...
        '''Save empiric KR to variable named:'',',...
        '''Save kernel KR to variable named:'',',...
        '''Save empiric Lift to variable named:'',',...
        '''Save kernel Lift to variable named:'',',...
        '''Save empiric Lift Ratio to variable named:'',',...
        '''Save kernel Lift Ratio to variable named:'',',...
        '''Save empiric IRL to variable named:'',',...
        '''Save kernel IRL to variable named:'',',...
        '''Save q for Lift to variable named:''};',...
        'varNames = {''AUC_emp'',''AUC_ker'',''Gini_emp'',''Gini_ker'',''KS_emp''',...
        ',''KS_ker'',''ival_emp'',''ival_ker'',''kr_emp'',''kr_ker'',''lift_emp''',...
        ',''lift_ker'',''LR_emp'',''LR_ker'',''IRL_emp'',''IRL_ker'',''q''};',...
        'items = {AUC_emp,AUC_ker,Gini_emp,Gini_ker,KS_emp,KS_ker,',...
        'ival_emp,ival_ker,kr_emp,kr_ker,y_emp,y_ker,LR_emp,LR_ker,IRL_emp,IRL_ker,q};',...% clear(varNames{:});',...
        'save ppp;save pp checkLabels varNames items invec;clear;load pp;delete pp.mat;invec=logical(invec);',...
        '[hdialog,ok_pressed]=export2wsdlg(checkLabels(invec),varNames(invec),items(invec),''Save Data'');'...
        'if ok_pressed G=get(gcf,''userdata'');set(G(19),''enable'',''on'');',...
        'clear G hdialog ok_pressed checkLabels varNames items;varNames=who;',...
        'save v varNames -append;save(''puvprom'',varNames{:},''-append'');end;load ppp;delete ppp.mat'];
    labelStr='var';
    varHndl=uicontrol( ...
        'Style','push', ...
        'Enable','off',...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.88,.1,.05,0.05], ...
        'String',labelStr, ...
        'Callback',call);
    
    % The FILE button
    labelStr='file';
    call='load v; uisave(varNames,''data_ks'')';
    fileHndl=uicontrol( ...
        'Style','push', ...
        'Enable','off',...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.93,.1,.05,0.05], ...
        'String',labelStr, ...
        'Callback',call);
    
    % The CLOSE button
    labelStr='Close';
    uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.88,.03,.1,0.05], ...
        'String',labelStr, ...
        'Callback',callbackStr);
    
    % The Print button
    labelStr='P';
    %     call1='load v;load w;figure;plot(X,y,''x'');hold on;';
    call1='curr=get(gcf,''CurrentAxes'');fig=figure;cc=copyobj(curr,fig);';
    call2='set(cc,''Position'',[0.08 0.08 0.85 0.85]);';
    uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.001,.96,.03,0.035], ...
        'String',labelStr, ...
        'Callback',[call1,call2]);
    
    hndlList=[roc_emp,roc_ker,Gini_emp,Gini_ker,KS_emp,KS_ker,...
        IV_emp,IV_ker,KR_emp,KR_ker,Lift_emp,Lift_ker,LR_emp,LR_ker,...
        IRL_emp,IRL_ker,qHndl,varHndl,fileHndl];
    set(gcf,'UserData',hndlList);
    %set(C,'Position',[0 0.0347 1.0000 0.9190]);
    set(C,'Position',[0.1059 0.1655 0.7700 0.6898]);
    %set(C,'Position',[1 1 .97 .9].*scrsz+[.01 .012 0 0]);
    set(C,'Visible','on');

end

